package com.razorfish.configuration.entities 
{
	import com.razorfish.configuration.condition.Condition;
	import com.razorfish.configuration.ConfigService;
	/**
	 * ...
	 * @author derek
	 */
	public class Group extends ConfigObject
	{
		public var condition:Condition;
		public var type:String;
		public var children:Vector.<SingleConfigObject>;
		public var uniqueName:String;
		
		public function Group(data:*, type:String, index:int) 
		{
			super(data);
			this.type = type;
			this.uniqueName = "{" + type + "_" + index + "}";
			init();
		}
		
		private function init():void
		{
			// init condition
			if (originalData.attribute(ConfigService.COND_NAME) != undefined)
				this.condition = new Condition(originalData.attribute(ConfigService.COND_NAME));
				
			// init children
			children = new Vector.<SingleConfigObject>();
			
			if (this.type == ConfigObjectType.ItemGroup)
			{
				for each (var item:XML in originalData.children())
				{
					children.push(new Item(item, this));
				}
			}
			else if (this.type == ConfigObjectType.PropertyGroup)
			{
				for each (var prop:XML in originalData.children())
				{
					children.push(new Property(prop, this));
				}
			}
			
			if (children.length < 1) children = null;
		}
		
		public function get isAvailable():Boolean
		{
			if (condition == null) return true;
			else return condition.result;
		}
	}
}
